import express from 'express'
import * as uuid from 'uuid'
import cors from 'cors'
const app = express()
// 启用CORS
app.use(cors());
const port = 3000
app.use(express.json())
app.get('/', (req, res) => {
  res.send('Hello World!')
})
app.post('/login', (req, res) => {
  const ip = req.ip;
  const { userName, passWord } = req.body;
  console.log(userName, passWord);
  if (userName === 'admin' && passWord === '123456') {
    res.send({
      code: 200,
      msg: '登录成功',
      data: {
        token: uuid.v4(),
        ip
      }
    })
  } else {
    res.send({
      code: 400,
      msg: '用户名或密码错误'
    })
  }
})
app.listen(port, () => {
  console.log(`Example app listening on port ${port}`)
})